package com.wdg.controller;

import com.wdg.pojo.Advert;
import com.wdg.pojo.Topic;
import com.wdg.pojo.User;
import com.wdg.service.IAroundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("provider_around")
public class AroundController {

    @Autowired
    private IAroundService aroundService;

    @PostMapping("/uploadTopic")
    public boolean uploadTopic(@RequestBody Topic topic){
        return aroundService.uploadTopic(topic) > 0;
    }

    @GetMapping("/getTopic/{page}")
    public List<Topic> getTopic(@PathVariable("page") int page){
        return aroundService.getTopic(page);
    }
//    登录和注册
    @PostMapping("/login")
    public User login(@RequestBody User user){
        return aroundService.login(user);
    }
    @PostMapping("/regist")
    public boolean regist(@RequestBody User user){
        return aroundService.regist(user) > 0;
    }

    @GetMapping("/getAllAdvert")
    public List<Advert> getAllAdvert(){
        return aroundService.getAllAdvert();
    }


    @GetMapping("getAllUser")
    public List<User> getAllUser(@RequestParam("page") int page){
       if (page < 0){
           return aroundService.getAllUsers();//大v
       }
        page = page * 10;
        return aroundService.getAllUser(page);//所有的用户有分页

    }

    //关注
    @PostMapping("/focus")
    public boolean focus(@RequestParam("uid") int uid, @RequestParam("uided") int uided){
        return aroundService.focus(uid,uided);
    }
    //取消关注
    @PostMapping("/delfocus")
    public boolean delfocus(@RequestParam("uid") int uid, @RequestParam("uided") int uided){
        return aroundService.delfocus(uid,uided);
    }
    //判断是否关注
    @PostMapping("/isfocus")
    public boolean isfocus(@RequestParam("uid") int uid, @RequestParam("uided") int uided){
        return aroundService.isfocus(uid,uided);
    }

    //收藏
    @PostMapping("/staroff")
    public boolean staroff(@RequestParam("uid") int uid, @RequestParam("cbid") String cbid){
        return aroundService.staroff(uid,cbid);
    }
    //取消收藏
    @PostMapping("/delstaroff")
    public boolean delstaroff(@RequestParam("uid") int uid, @RequestParam("cbid") String cbid){
        return aroundService.delstaroff(uid,cbid);
    }
    //判断是否收藏
    @PostMapping("/isstaroff")
    public boolean isstaroff(@RequestParam("uid") int uid, @RequestParam("cbid") String cbid){
        return aroundService.isstaroff(uid,cbid);
    }
}
